//
//  PushSegue.m
//  ybzj
//
//  Created by liyuan on 15/7/12.
//  Copyright (c) 2015年 liyuan. All rights reserved.
//

#import "PushSegue.h"

@implementation PushSegue





- (void) perform
{
    UIViewController *desViewController = (UIViewController *)self.destinationViewController;
    
    UIView *srcView = ((UIViewController *)self.sourceViewController).view;
    UIView *desView = [desViewController view];
    
   // desView.transform = srcView.transform;
    //desView.bounds = srcView.bounds;
    
    
    if(_isLandscapeOrientation)
    {
        if(_isDismiss)
        {
            desView.center = CGPointMake(srcView.center.x, srcView.center.y  - desView.frame.size.height);
        }
        else
        {
            desView.center = CGPointMake(srcView.center.x, srcView.center.y  + desView.frame.size.height);
        }
    }
    else
    {
        if(_isDismiss)
        {
            desView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, desView.center.y);
        }
        else
        {
            desView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, desView.center.y);
        }
    }
    
    
    UIWindow *mainWindow = [[UIApplication sharedApplication].windows objectAtIndex:0];
    //if(![desView.superview isEqual:mainWindow]){
    [mainWindow addSubview:desView];
    //}
    
    // slide newView over oldView, then remove oldView
    [UIView animateWithDuration:0.05
                     animations:^{
                         desView.center = CGPointMake(srcView.center.x, desView.center.y);
                                                  if(_isLandscapeOrientation)
                         {
                             if(_isDismiss)
                             {
                                 srcView.center = CGPointMake(srcView.center.x, srcView.center.y + srcView.frame.size.height);
                             }
                             else
                             {
                                 srcView.center = CGPointMake(srcView.center.x, srcView.center.y - srcView.frame.size.height);
                             }
                         }
                         else
                         {
                             if(_isDismiss)
                             {
                                 srcView.center = CGPointMake(srcView.center.x + srcView.frame.size.width, srcView.center.y);
                             }
                             else
                             {
                                 srcView.center = CGPointMake(srcView.center.x - srcView.frame.size.width, srcView.center.y);
                             }
                         }
                         
                     }
                     completion:nil];
    
    
}
@end


